package com.dream21th.generate.util;


/**
 * @Auther: hp
 * @Date: 2019/6/11 22:25
 * @Description:
 */
public class TypeTranferUtils {

    public static String dbToJava(String dbType){
        String javaType="String";
        if(dbType.endsWith("int") || dbType.equals("integer")){
            javaType="Integer";
        }else if(dbType.equals("bigint")){
            javaType="Long";
        }else if(dbType.equals("decimal")){
            javaType="BigDecimal";
        }else {
            javaType="String";
        }


        return javaType;
    }

    public static String dbColumnToJava(String columnName){
        String[] split = columnName.split("_");
        StringBuilder builder=new StringBuilder(split[0]);
        for (int i=1;i<split.length;i++){
            builder.append(split[i].substring(0,1).toUpperCase()+split[i].substring(1));
        }
        return builder.toString();
    }

    public static String tableNameToJava(String tableName){
        String[] split = tableName.split("_");
        StringBuilder builder=new StringBuilder();
        for (int i=0;i<split.length;i++){
            builder.append(split[i].substring(0,1).toUpperCase()+split[i].substring(1));
        }
        return builder.toString();
    }
}
